import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    orders: [] // 准备接受订单列表
  },
  mutations: {
    changeOrders(state, val) {
      val.forEach(item => {
        item.check = false
      })
      state.orders = val
    }
  },
  // 处理异步逻辑的方法
  actions: {
    getOrders({commit}) {
      axios.get('data.json').then(res => {
        // console.log(res);
        commit('changeOrders', res.data.goods)
      })
    }
  },
  modules: {
  }
})
